class A(models.Model):
  pass

class B(models.Model):
    a = models.ForeignKey(B)
    pass

a = A.objects.get(pk=0)
b = B.objects.get(pk=0)

# database
## Table A:
# pk other fielsd
# 0  xxx
# 1  yyy
# 2  zzz

## Table B
# pk fk other fielsd
# 0  0  xxx
# 1  1  xxx
# 2  0  xxx

# then we can do like these
a.b_set.all() # will return a queryset like [b0, b2]


b.a # will return a A instance a0

a.b_set.all().values('id', 'a__id') # just like select b.pk, a.pk from b left join a where a.pk=b.a
